/**
 * Created by lvliqi on 2016/7/12.
 */
/*
 火爆投篮
 扫码
 点击开始
 手动输入
 一句少
 */

var express = require("express");
var router = express.Router();
var status_enum = require("../status_enum");
var activity_enum = require("./activity_enum");

var activityId = activity_enum.FREE_THROW;

router.post("/check", function (req, res) {
    var Queue = M("index.queue");
    var returnData = null;

    Queue.find({
        where: {
            activityId: activityId,
            status: status_enum.PLAY_BTN
        }
    }).then(function (data) {
        if (!data) throw new Error("no data");
        returnData = data;

        return Queue.update({
            status: status_enum.PLAYING
        }, {
            where: {
                id: data.id
            }
        });
    }).then(function () {
        return res.json({
            errno: 0,
            participantId: returnData.participantId
        })
    }).catch(function (err) {
        res.json({
            errno: 10001,
            errdesc: err.message
        })
    });
});
module.exports = router;